/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GamesPlayedComponent.java
 *
 * Created on 18/Jul/2011, 19:55:58
 */

package intopo.demonstrator.partnerclassification.gui;

import intopo.demonstrator.partnerclassification.Parameters;
import intopo.demonstrator.partnerclassification.Partner;
import intopo.demonstrator.partnerclassification.Statistics;

import java.awt.Dimension;

/**
 *
 * @author pedro
 */
public class GamesPlayedComponent
	extends AbstractStatisticsComponent
	implements java.io.Serializable
{
	transient Partner[] partners;
	
    /**
	  * Creates new form BeanForm
	  */
	public GamesPlayedComponent ()
	{
		parametersChanged ();
		setXLabel ("Partners");
		setTitle ("Games Played");
		addData (new GamesPlayed ());
		setMinimumSize (new Dimension (200, 200));
		setPreferredSize (new Dimension (300, 300));
		setMaximumSize (new Dimension (1000, 1000));
	}

	void parametersChanged ()
	{
		this.partners = new Partner [Model.parameters.getPartners ().size ()];
		Model.parameters.getPartners ().toArray (this.partners);
		TicLabel[] tics = new TicLabel [Model.parameters.getPartners ().size ()];
		int i = 0;
		for (Partner p : Model.parameters.getPartners ()) {
			tics [i] = new TicLabel (p.getBehaveAcceptablyProbability ().toString(), i);
			this.partners [i] = p;
			i++;
		}
		this.setXTics (tics);
		this.setYTics (0, 0.2, 1);
		this.setXRange (-0.5, tics.length - 0.5);
		this.setYRange (0, 1);
		repaint ();
	}

	/**
	 * Update this combination after a new transition of the partner classification model.
	 *
	 * The range of the vertical axis is updated.
	 */
	void newTransition ()
	{
		int range = Model.statistics.getGamesPlayed ();
//		System.out.println (statistics);
		this.setYRange (0, range);
		if (range < 10)
			this.setYTics (0, 1, range);
		else
			this.setYTics (0, range / 10, range);
		repaint ();
	}
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
    private void initComponents() {

    }
    // </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

	class GamesPlayed
		extends AbstractData
	{
		GamesPlayed ()
		{
			super (java.awt.Color.BLUE, null, null, true, false, false);
		}
		@Override
		public int size ()
		{
			return Model.parameters.getPartners().size();
		}

		@Override
		public double x(int index)
		{
			return index;
		}

		@Override
		public double y(int index)
		{
			return Model.statistics.getPartnerData (partners [index]).getGamesPlayed();
		}
	}
}
